#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>

using namespace std;
bool vis[11] = { false };
int n;

int dfs(vector<int>& arr, int start)
{
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (vis[i] == false && vis[arr[i] - 1] == true)
        {
            return 0;
        }
        if (vis[i] == false)
        {
            vis[i] = true;
            res += dfs(arr, start + 1);
            vis[i] = false;
        }
    }
    if (start == n - 1) return 1;
    return res;
}

int main()
{
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    cout << dfs(arr, 0);
    return 0;
}